package cn.tedu.boot011.util;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
    private static DruidDataSource dds;
    static {
      dds = new DruidDataSource();
      dds.setUsername("root");
      dds.setPassword("123456");
      dds.setUrl("jdbc:mysql://localhost:3306/bbsdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
      dds.setInitialSize(5);
      dds.setMaxActive(10);

    }

    /**
     * 获取数据库连接
     * @return
     * @throws SQLException
     */
    public static Connection getConnection() throws SQLException {
//        return  DriverManager.getConnection("jdbc:mysql://localhost:3306/bbsdb" +
//                "?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
//                "root", "123456");

        return dds.getConnection();
    }

}
